#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
小巧文件清理工具 - 重构版本
职责单一，模块化设计
"""

import tkinter as tk
from src.core import FileCleanerCore
from src.handlers import EventHandlers
from src.ui_components import UIComponents
from src.scan_workers import ScanWorkers


class FileCleanerGUI(EventHandlers, UIComponents, ScanWorkers):
    """文件清理工具主界面"""
    
    def __init__(self):
        self.root = tk.Tk()
        self.core = FileCleanerCore()
        self.current_scan_data = {}
        self.default_expand_levels = 2
        self.checked_items = {}
        
        # 存储各类型的原始数据用于筛选
        self.dev_original_data = []
        self.temp_original_data = []
        self.large_original_data = []
        self.dup_original_data = {}
        
        # 初始化排序状态管理
        self.sort_states = {
            'temp': {'column': None, 'reverse': False},
            'dup': {'column': None, 'reverse': False},
            'large': {'column': None, 'reverse': False},
            'dev': {'column': None, 'reverse': False}
        }
        
        self.setup_ui()
        
    def run(self):
        """运行主程序"""
        self.add_log("=== 西红柿轰炸机专用工具已启动 ===", 'success')
        self.add_log("提示: 选择要扫描的目录，然后点击相应的扫描按钮", 'info')
        self.add_log(f"当前主题: {self.get_current_theme_name()}", 'info')
        
        if not self.check_admin_privileges():
            self.add_log("[WARN] 当前未以管理员身份运行，某些系统文件可能无法访问", 'warning')
        
        self.root.mainloop()


def main():
    """程序入口"""
    try:
        app = FileCleanerGUI()
        app.run()
    except Exception as e:
        import traceback
        error_msg = f"程序启动失败: {str(e)}\n\n详细错误:\n{traceback.format_exc()}"
        try:
            from tkinter import messagebox
            messagebox.showerror("启动错误", error_msg)
        except:
            print(error_msg)


if __name__ == "__main__":
    main()